home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 March
/
CMCD0305.ISO
/
Software
/
Shareware
/
Utilitare
/
emu
/
Emu8086_Setup_307c.exe
/
{app}
/
Samples
/
fahrenheit.asm
< prev
next >
Wrap
Assembly Source File
|
2002-11-15
|
1KB
|
59 lines
; Centigrade (Celsius) to Fahrenheit
; calculation and vice-versa.
; (not very accurate, since using
; integer divide, it may not work
; for some values as well...).
; This program has no input/output from
; the user, so in order to see the result
; it maybe useful to select "Variables"
; from "View" menu of the emulator.
; Another way to see the output is to
; use PRINT_NUM procedure from "emu8086.inc",
; see "Part 5" in tutorials.
; (since we get result in AL, you should use
; CBW instruction before printing out,
; because PRINT_NUM prints a signed number
; in AX register).
#MAKE_COM#
ORG 100h
JMP start
tc DB 10 ; t Celsius.
tf DB 0 ; t Fahrenheit.
result1 DB ? ; result in Fahrenheit.
result2 DB ? ; result in Celsius.
start:
; convert Celsius to Fahrenheit according
; to this formula: f = c * 9 / 5 + 32
MOV CL, tc
MOV AL, 9
IMUL CL
MOV CL, 5
IDIV CL
ADD AL, 32
MOV result1, AL
; convert Fahrenheit to Celsius according
; to this formula: c = (f - 32) * 5 / 9
MOV CL, tf
SUB CL, 32
MOV AL, 5
IMUL CL
MOV CL, 9
IDIV CL
MOV result2, AL
RET